package com.xgkj.diyiketang.activity;

import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.easyvaas.sdk.core.EVSdk;
import com.xgkj.diyiketang.EatShowApp;
import com.xgkj.diyiketang.R;
import com.xgkj.diyiketang.data.AdvertiseInfo;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.fragment.Fragment_MingShi;
import com.xgkj.diyiketang.fragment.MyFragment;
import com.xgkj.diyiketang.fragment.ShouYeFragment;
import com.xgkj.diyiketang.fragment.TuiJianFragment;
import com.xgkj.diyiketang.fragment.ZhiboFirstPageFragment;
import com.xgkj.diyiketang.http.engine.ShowToastTaskEventListener;
import com.xgkj.diyiketang.http.engine.TaskEventListener;
import com.xgkj.diyiketang.task.AdvertisementTask;
import com.xgkj.diyiketang.task.GetUserDetailTask;
import com.xgkj.diyiketang.task.LiveDetailTask;
import com.xgkj.diyiketang.util.DialogUtil;
import com.xgkj.diyiketang.util.EatShowSetting;
import com.xgkj.diyiketang.util.PalLog;
import com.xgkj.diyiketang.util.ViewUtil;
import com.xgkj.diyiketang.yizhibo.Constants;
import com.xgkj.diyiketang.yizhibo.PlayerNewActivity;

import java.util.ArrayList;
import java.util.List;

import cn.jpush.android.api.JPushInterface;


public class MainActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener, View.OnClickListener {
    private static final String TAG = "HomeActivity";
    private Context mContext;
    private int mCheckId;
    private int beforeCheckId;
    private int last_index = 0;
    private RadioGroup mRadioGroup;
    private Fragment anchorFragment;
    private Fragment tuijianFragment;
    private Fragment myFragment;
    private Fragment shouyeFragment;
    private Fragment zhiboFirstPageFragment;
    private Fragment zhiboFragment;
    private RadioButton videoBtn;
    private RadioButton anchorBtn;
    private RadioButton tuijianBtn;
    private RadioButton myBtn;
    private RadioButton zhiboBtn;
    private int detailTaskId = -1;
    private EatShowUserInfo userInfo;
    private static final String FRAGMENT_KEY_ANCHOR = "anchor";
    private static final String FRAGMENT_KEY_TUIJIAN = "tuijian";
    private static final String FRAGMENT_KEY_MY = "my";
    private static final String CURRENT_INDEX = "current_index";
    private static final String FRAGMENT_KEY_SHOUYE = "shouye";
    private static final String FRAGMENT_KEY_ZHIBO = "zhibo";
    private PopupWindow popWindow;
    private ImageView mCha;
    private int goXyb = 1;
    private EatShowUserInfo zhiboInfo;
    private String vid;
    private int liveType;
    private String headUrl;
    private String anchor;
    private String openUrl;

    ImageView diolog_relative_image, diolog_relative_btn;
    LinearLayout diolog_relative;
    private String liveState;
    private String tag;
    private String flag;
    private String isPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = this;
//        getUserDetail();
        initView();
        initData();
        restoreFragment(savedInstanceState);
        initFragment();
        mRadioGroup.setOnCheckedChangeListener(this);
        doPush();
        if (last_index != 0) {
            mRadioGroup.check(last_index);
        } else {
            videoBtn.setChecked(true);
        }
        getDiolog();
    }

    private final int WRITE_PERMISSION_REQ_CODE = 100;


    private void initData() {

        if (Build.VERSION.SDK_INT >= 23) {

            List<String> permissions = new ArrayList<>();
            if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)) {
                permissions.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            }
            if (permissions.size() != 0) {
                ActivityCompat.requestPermissions(this,
                        (String[]) permissions.toArray(new String[0]),
                        WRITE_PERMISSION_REQ_CODE);
            }
        }

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case WRITE_PERMISSION_REQ_CODE:
                for (int ret : grantResults) {
                    if (ret != PackageManager.PERMISSION_GRANTED) {
                        return;
                    }
                }
                String userid = EatShowSetting.getInstance(mContext).getUserId();
                initSdk(userid);
                break;
            default:
                break;
        }
    }

    //初始化直播sdk
    private void initSdk(String userId) {
        String appID;
        if (TextUtils.isEmpty(Constants.appID)) {
            return;
        } else {
            appID = Constants.appID;
        }

        String accessKey;
        if (TextUtils.isEmpty(Constants.accessKey)) {
            return;
        } else {
            accessKey = Constants.accessKey;
        }

        String secretKey;
        if (TextUtils.isEmpty(Constants.secretKey)) {
            return;
        } else {
            secretKey = Constants.secretKey;
        }

        String userID;
        if (TextUtils.isEmpty(EatShowApp.getACache().getAsString(Constants.USER_ID))) {
            return;
        } else {
            userID = EatShowApp.getACache().getAsString(Constants.USER_ID);
        }

        EVSdk.setInitListener(new EVSdk.OnSDKInitListener() {
            @Override
            public void onSuccess() {
            }

            @Override
            public void onFailed(int code, String msg) {
            }
        });
        EVSdk.init(getApplicationContext(), appID, accessKey, secretKey, userId);
    }

    private int advertiseId = 6;

    private void getDiolog() {
        AdvertisementTask adtask = new AdvertisementTask("6", "");
        adtask.addListener(mListener);
        advertiseId = getEatShowApp().getTaskManager().addTask(adtask);
    }

    private void doPush() {
        Intent intent1 = getIntent();
        if (intent1 == null) {
            videoBtn.setChecked(true);
            return;
        }
        Bundle bundle = intent1.getExtras();
        if (bundle == null) {
            videoBtn.setChecked(true);
            return;
        }
        String extra_string = bundle.getString(JPushInterface.EXTRA_EXTRA);
        if (!ViewUtil.isNull(extra_string)) {
            JSONObject jsonObject = JSON.parseObject(extra_string);
            PalLog.e(TAG, jsonObject.toString());
            int type = 0;
            type = jsonObject.getIntValue("type");
            String videoId = jsonObject.getString("id");
            if (!TextUtils.isEmpty(jsonObject.getString("isMoive2"))) {
                String isMoive2 = jsonObject.getString("isMoive2");
            }
            if (type == 1) {
                goXyb = 1;
            } else if (type == 0 || type == 6) {
                goXyb = 3;
            } else {
                goXyb = 2;
            }
            if (type == 4) {
                String icon = jsonObject.getString("anchorLogo");
                String mBusinessLogo = jsonObject.getString("businessBigLogo");
                Intent bdInent = new Intent(mContext, YuFanDetailActivity.class);
                bdInent.putExtra("ACTIVEID", videoId);
                bdInent.putExtra("LOGO", icon);
                bdInent.putExtra("SELLERLOGO", mBusinessLogo);
                startActivity(bdInent);
            } else if (type == 1) {
                String uId = jsonObject.getString("anchorId");
                String youkuVideoId = jsonObject.getString("path");
//                Intent videoIntent = new Intent(mContext, VideoDetailActivity.class);
                Intent videoIntent = new Intent(mContext, GuoxueVideoTwoActivity.class);
                videoIntent.putExtra("videoid", videoId);
                videoIntent.putExtra("UID", uId);
                videoIntent.putExtra("YOUKUVIDEOID", youkuVideoId);
                startActivity(videoIntent);
            } else if (type == 2) {
                String icon = jsonObject.getString("anchorLogo");
                String areaName = jsonObject.getString("areaName");
                Intent bdInent = new Intent(mContext, YueFanSJDetailActivity.class);
                bdInent.putExtra("ACTIVEID", videoId);
                bdInent.putExtra("LOGO", icon);
                bdInent.putExtra("SHANGQUAN", areaName);
                startActivity(bdInent);
            } else if (type == 3) {
                String result = jsonObject.getString("resultContent");
                Intent tjIntent = new Intent(mContext, ChuangJianChengGongActivity.class);
                tjIntent.putExtra("FROM", "RESULT");
                tjIntent.putExtra("RESULT", result);
                startActivity(tjIntent);
            } else if (type == 6) {
                zhiboBtn.setChecked(true);
                if (getEatShowApp().getmUserInfo() != null) {
                    zhiboInfo = JSON.parseObject(extra_string, EatShowUserInfo.class);
                    vid = zhiboInfo.getVid();
                    isPlayer = zhiboInfo.getIsMoive2();
                    liveState = zhiboInfo.getLiveState();
                    liveType = zhiboInfo.getLiveType();
                    anchor = zhiboInfo.getNickName();
                    headUrl = zhiboInfo.getUserLogo();
                    EatShowUserInfo userInfo = EatShowApp.getInstance().getmUserInfo();
                    String userId = null;
                    if (userInfo != null) {
                        userId = userInfo.getUserId();
                    }
                    String anchorId = zhiboInfo.getUserId();
                    boolean isSelf = false;
                    if (anchorId != null && anchorId.equals(userId)) {
                        isSelf = true;
                    }

                    if (isSelf || liveType == 0) {
                        Intent intent = new Intent(mContext, PlayerNewActivity.class);
                        intent.putExtra(Constants.EXTRA_KEY_VIDEO_ID, vid);
                        intent.putExtra(Constants.ZHIBO_PLAY, isPlayer);
                        intent.putExtra("videoid", videoId);
                        intent.putExtra(Constants.LIVE_STATE, liveState);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                    } else if (liveType == 1) {
                        //收费
                        doGetAnchorInfo(vid);
                    } else if (liveType == 2) {
                        //密码
                        Intent intent = new Intent(mContext, ZhiboPasswordActivity.class);
                        intent.putExtra("head_url", headUrl);
                        intent.putExtra("nickname", anchor);
                        intent.putExtra(Constants.ZHIBO_PLAY, isPlayer);
                        intent.putExtra(Constants.EXTRA_KEY_VIDEO_ID, vid);
                        intent.putExtra(Constants.LIVE_STATE, liveState);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                    }
                }

            }
        }
    }

    private int mtaskId = 1;

    private void doGetAnchorInfo(String mVid) {
        LiveDetailTask dtask = new LiveDetailTask(mVid);
        dtask.addListener(mListener);
        mtaskId = getEatShowApp().getTaskManager().addTask(dtask);
    }

    private TaskEventListener mListener = new ShowToastTaskEventListener(this) {
        @Override
        public void handleTaskCompleted(int taskId, int result, Object data) {
            super.handleTaskCompleted(taskId, result, data);
            if (taskId == mtaskId) {
                if (data != null) {
                    EatShowUserInfo info = (EatShowUserInfo) data;
                    if (liveType == 1 && info.getIsCharge() == 0) {
                        String title = zhiboInfo.getLiveTitle();
                        String fee = zhiboInfo.getFee();
                        Intent intent = new Intent(mContext, GouMaiKeChengActivity.class);
                        intent.putExtra("From", 1);
                        intent.putExtra("TITLE", title);
                        intent.putExtra("ZUOZHE", anchor);
                        intent.putExtra("FEE", fee);
                        intent.putExtra(Constants.ZHIBO_PLAY, isPlayer);
                        intent.putExtra(Constants.EXTRA_KEY_VIDEO_ID, vid);
                        intent.putExtra(Constants.LIVE_STATE, liveState);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                    } else {
                        Intent intent = new Intent(mContext, PlayerNewActivity.class);
                        intent.putExtra(Constants.EXTRA_KEY_VIDEO_ID, vid);
                        intent.putExtra(Constants.ZHIBO_PLAY, isPlayer);
//                        intent.putExtra("videoid", videoId);
                        intent.putExtra(Constants.LIVE_STATE, liveState);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mContext.startActivity(intent);
                    }
                }
            }

            if (taskId == advertiseId) {
                if (data != null) {
                    List<AdvertiseInfo> adList = (List<AdvertiseInfo>) data;
//                    if (adList == null || adList.size() == 0) {
//                        return;
//                    } else {
//                        ArrayList<String> imgurlList = new ArrayList<String>();
//                        ArrayList<String> banner_text_list = new ArrayList<String>();
//                        final ArrayList<String> urlList = new ArrayList<String>();
//                        for (AdvertiseInfo adInfo : adList) {
//                            imgurlList.add(adInfo.getImageUrl());
//                            banner_text_list.add(adInfo.getTitle());
//                            urlList.add(adInfo.getUrl());
//                        }


//                        if (adList.size() > 0){
////                            mRadioGroup.setBackgroundColor(Color.parseColor("#a9000000"));
//                            diolog_relative.setVisibility(View.VISIBLE);
//                            ImageCache.getInstance(mContext).
//                                    loadBitmapToView(diolog_relative_image, adList.get(0).getImageUrl(),
//                                            new ViewUtil.Size(ViewUtil.dip2px(mContext, 1056), ViewUtil.dip2px(mContext, 1356)));
//
//                        }


//                    }
                }
            }
        }

        @Override
        public void handleTaskError(int taskId, int errorCode, String errorMsg) {
            super.handleTaskError(taskId, errorCode, errorMsg);
        }
    };


    @Override
    protected void onNewIntent(Intent intent) {

        super.onNewIntent(intent);
        setIntent(intent);
        doPush();
        int ssds = intent.getIntExtra("Flag", 0);
        if (ssds == 678) {
            zhiboBtn.setChecked(true);
            ssds = 0;
        }
    }

    private void initView() {
        Intent intent = getIntent();
        openUrl = intent.getStringExtra("URL");

//        PalLog.e("跳转链接", openUrl);
        if (intent != null && !ViewUtil.isNull(openUrl)) {
            Intent adIntent = new Intent(Intent.ACTION_VIEW);
            adIntent.setData(Uri.parse(openUrl));
            mContext.startActivity(adIntent);
        }


        mRadioGroup = (RadioGroup) findViewById(R.id.home_tab);
        videoBtn = (RadioButton) findViewById(R.id.video);
        anchorBtn = (RadioButton) findViewById(R.id.anchor);
        zhiboBtn = (RadioButton) findViewById(R.id.zhibo);
        tuijianBtn = (RadioButton) findViewById(R.id.tuijian);
        myBtn = (RadioButton) findViewById(R.id.my);

        diolog_relative_image = (ImageView) findViewById(R.id.diolog_relative_image);
        diolog_relative_btn = (ImageView) findViewById(R.id.diolog_relative_btn);
        diolog_relative = (LinearLayout) findViewById(R.id.diolog_relative);
        diolog_relative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                diolog_relative.setVisibility(View.GONE);
            }
        });
        diolog_relative_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getEatShowApp().getmUserInfo() == null) {
                    startActivity(new Intent(MainActivity.this, LoginActivity.class));
                } else {
                    diolog_relative.setVisibility(View.GONE);

//                    Intent zintent = new Intent(MainActivity.this, YuZhiBoActivity.class);
//                    zintent.putExtra("FROM", "ZHIBO");
//                    zintent.putExtra("FANSNUM", 0);
//                    startActivity(zintent);
                }

            }
        });
    }

    private void initPopWindow() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.discoverlayout,
                null);
        ((TextView) view.findViewById(R.id.yuefan))
                .setOnClickListener(this);
        ((TextView) view.findViewById(R.id.mishi))
                .setOnClickListener(this);
        popWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        mCha = (ImageView) view.findViewById(R.id.pop_down_img);
        mCha.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindow.dismiss();
            }
        });
        popWindow.setBackgroundDrawable(new ColorDrawable());
        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(true);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(CURRENT_INDEX, mRadioGroup.getCheckedRadioButtonId());
    }

    private void restoreFragment(Bundle savedInstanceState) {
        if (savedInstanceState != null) {
            FragmentManager fm = getSupportFragmentManager();
            shouyeFragment = fm.findFragmentByTag(FRAGMENT_KEY_SHOUYE);//fm.getFragment(savedInstanceState,FRAGMENT_KEY_SHOUYE);
            anchorFragment = fm.findFragmentByTag(FRAGMENT_KEY_ANCHOR);//fm.getFragment(savedInstanceState, FRAGMENT_KEY_ANCHOR);
            tuijianFragment = fm.findFragmentByTag(FRAGMENT_KEY_TUIJIAN);//fm.getFragment(savedInstanceState, FRAGMENT_KEY_TUIJIAN);
            myFragment = fm.findFragmentByTag(FRAGMENT_KEY_MY);//fm.getFragment(savedInstanceState, FRAGMENT_KEY_MY);
            last_index = savedInstanceState.getInt(CURRENT_INDEX);
        }
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            showExitDialog();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private void showExitDialog() {
        DialogUtil.createDialog(mContext, -1, getString(R.string.prompt), getString(R.string.exit_app), getString(R.string.ok), getString(R.string.cancle), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                getEatShowApp().exitApp();
            }
        }, null);
    }

    private void initFragment() {
        if (shouyeFragment == null) {
            shouyeFragment = new ShouYeFragment();
        }

        if (anchorFragment == null) {
            anchorFragment = new Fragment_MingShi();
        }

        if (zhiboFirstPageFragment == null) {
            zhiboFirstPageFragment = new ZhiboFirstPageFragment();
        }
        if (tuijianFragment == null) {
            tuijianFragment = new TuiJianFragment();
        }

        if (myFragment == null) {
            myFragment = new MyFragment();
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {

        if (mCheckId == checkedId) {
            return;
        }
        beforeCheckId = mCheckId;
        mCheckId = checkedId;
        switch (checkedId) {
            case R.id.video:
                //               replaceFragment(FRAGMENT_KEY_VIDEO, videoFragment);
                replaceFragment(FRAGMENT_KEY_SHOUYE, shouyeFragment);
                break;
            case R.id.anchor:
                if (getEatShowApp().getmUserInfo() != null) {
                    replaceFragment(FRAGMENT_KEY_ANCHOR, anchorFragment);
                    ShouYeFragment frg = (ShouYeFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_KEY_SHOUYE);
                    frg.hidePopSchool();
                } else {
                    videoBtn.setChecked(true);
                    startActivity(new Intent(mContext, LoginActivity.class));
                }
                break;
            case R.id.zhibo:
                if (getEatShowApp().getmUserInfo() != null) {
                    replaceFragment(FRAGMENT_KEY_ZHIBO, zhiboFirstPageFragment);
                    ShouYeFragment frg = (ShouYeFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_KEY_SHOUYE);
                    frg.hidePopSchool();
                } else {
                    videoBtn.setChecked(true);
                    startActivity(new Intent(mContext, LoginActivity.class));
                }
                break;
            case R.id.tuijian:
                if (getEatShowApp().getmUserInfo() != null) {
                    replaceFragment(FRAGMENT_KEY_TUIJIAN, tuijianFragment);
                    ShouYeFragment frg = (ShouYeFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_KEY_SHOUYE);
                    frg.hidePopSchool();
                } else {
                    videoBtn.setChecked(true);
                    startActivity(new Intent(mContext, LoginActivity.class));
                }
                break;
            case R.id.my:
                if (getEatShowApp().getmUserInfo() != null) {
                    replaceFragment(FRAGMENT_KEY_MY, myFragment);
                    ShouYeFragment frg = (ShouYeFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_KEY_SHOUYE);
                    frg.hidePopSchool();
                } else {
                    videoBtn.setChecked(true);
                    startActivity(new Intent(mContext, LoginActivity.class));
                }
                break;
            default:
                break;
        }

    }

    private void replaceFragment(String tag, Fragment mFragment) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction fts = fm.beginTransaction();
        if (shouyeFragment.isAdded()) {
            fts.hide(shouyeFragment);
        }

        if (anchorFragment.isAdded()) {
            fts.hide(anchorFragment);
        }


        if (zhiboFirstPageFragment.isAdded()) {
            fts.hide(zhiboFirstPageFragment);
        }

        if (tuijianFragment.isAdded()) {
            fts.hide(tuijianFragment);
        }

        if (myFragment.isAdded()) {
            fts.hide(myFragment);
        }


        if (mFragment.isAdded()) {
            fts.show(mFragment);
        } else {
            fts.add(R.id.content, mFragment, tag);
        }

        fts.commitAllowingStateLoss();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.yuefan:
                Intent yfIntent = new Intent(mContext, YueFanActivity.class);
                startActivity(yfIntent);
                popWindow.dismiss();
                break;
            case R.id.mishi:
                //Toast.makeText(mContext, R.string.zanweikaifang, Toast.LENGTH_SHORT).show();
                Intent msIntent = new Intent(mContext, MiShiActivity.class);
                startActivity(msIntent);
                popWindow.dismiss();
                break;

        }

    }


    public void showFirstPage() {
        if (!videoBtn.isChecked()) {
            videoBtn.setChecked(true);
        }
    }

    public int getGoXyb() {
        return goXyb;
    }

    public void setGoXyb(int goXyb) {
        this.goXyb = goXyb;
    }

    private void getUserDetail() {
        GetUserDetailTask task = new GetUserDetailTask();
        task.addListener(new MyListener(mContext));
        detailTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

    class MyListener extends ShowToastTaskEventListener {
        public MyListener(Context context) {
            super(context);
        }

        @Override
        public void handleTaskCompleted(int taskId, int result, Object data) {
            super.handleTaskCompleted(taskId, result, data);
            if (detailTaskId == taskId)
                if (data != null) {
                    userInfo = (EatShowUserInfo) data;
                    if (userInfo != null) {
                        if (userInfo.getList() != null && userInfo.getList().size() > 0) {
                            for (int i = 0; i < userInfo.getList().size(); i++) {
                                String xueyuan = userInfo.getList().get(i).xueyuan;
                                if (xueyuan.equals("3d9513eb1b674af98de226b315765e3f")) {
                                    if (userInfo.getList().get(i).shenfen != null) {
                                        tag = "1";
                                        EatShowApp.tag = tag;
                                    }
                                }
                            }
                        }
                        if (userInfo.getIdentityList() != null && userInfo.getIdentityList().size() > 0) {
                            for (int i = 0; i < userInfo.getIdentityList().size(); i++) {
                                String xueyuan = userInfo.getIdentityList().get(i).xueyuan;
                                //转运
                                if (xueyuan.equals("3d9513eb1b674af98de226b315765e3f")) {
                                    String shenfen = userInfo.getIdentityList().get(i).shenfen;
                                    if (shenfen != null) {
                                        flag = "1";
//                                        EatShowApp.getACache().put("flag",flag);
                                    }
                                }
                            }
                        }

                    }

                }
        }

        @Override
        public void handleTaskError(int taskId, int errorCode, String errorMsg) {
            super.handleTaskError(taskId, errorCode, errorMsg);
        }

        @Override
        public void handleTaskMessage(int taskId, Object data) {
            super.handleTaskMessage(taskId, data);
        }
    }
}
